using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows.Markup;
using Rhizome.Bindings;
using Rhizome.Contract;
using Rhizome.Contract.Diag;
using Rhizome.Model.Validation;

namespace Rhizome.Model
{
	[ContentProperty("Property")]
	public abstract class PropertyActionBase : ActionBase<object>, IValidate
	{
		/// <summary>
		/// Property to use
		/// XAML "macro": sets BindingProperty
		/// </summary>
		public string Property
		{
			get
			{
				var b = Binding;
				return b == null ? null : b.Property;
			}
			set { SetValue(BindingProperty, BindingProxy.Create(value)); }
		}

		protected BindingProxy Binding
		{
			[DebuggerStepThrough]
			get { return GetValue(BindingProperty); }
		}

		#region IValidate Members

		public virtual IEnumerable<IValidationResult> GetValidationResults()
		{
			if (Plant == null)
				yield return ValidationResult.PlantIsNull;

			if (String.IsNullOrEmpty(Property))
				yield return ValidationResult.PropertyNotSet;
		}

		#endregion
	}
}